package com.meisupic.copyright.amdin.controller;

import com.meisupic.copyright.domain.query.RealNameAuthQuery;
import com.meisupic.copyright.domain.vo.AccountInfoVo;
import com.meisupic.copyright.domain.vo.PageRealNameAuthVo;
import com.meisupic.copyright.service.IAccountService;
import com.meisupic.copyright.service.IRealNameAuthService;
import com.meisupic.copyright.support.PageResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * creation wuxun
 *
 * @Date 2018/1/22 上午11:19
 */
@RestController
@RequestMapping("/admin/realnameauth")
public class RealnameAuthAdminController {

  @Autowired
  private IRealNameAuthService realNameAuthService;

  @Autowired
  private IAccountService accountService;

  @GetMapping(value = "/page")
  public PageResponse<PageRealNameAuthVo> queryPage(RealNameAuthQuery realNameAuthQuery,
      @PageableDefault(sort = {"createTime"}, direction = Direction.DESC) Pageable pageable) {
    PageRequest pageRequest = new PageRequest(pageable.getPageNumber() - 1, pageable.getPageSize(),
        pageable.getSort());
    Page<PageRealNameAuthVo> sysDicPoPage = realNameAuthService
        .findPage(realNameAuthQuery, pageRequest);
    PageResponse<PageRealNameAuthVo> pageResponse = new PageResponse<>(
        sysDicPoPage.getTotalElements(), sysDicPoPage.getContent());
    return pageResponse;
  }

  @GetMapping(value = "/getUserInfo")
  public AccountInfoVo getAccountInfo(Long userId) {
    return accountService.getAccountInfo(userId);
  }


}
